package name.bingo.bing.pay.service.message.controller;

import name.bingo.bing.pay.service.message.mqservice.Producer;
import org.apache.activemq.broker.BrokerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;
import java.util.Date;

/**
 * create by yanbing on 2018/8/28 10:10
 */
@RestController
@RequestMapping("mq")
public class AvtiveMqController {
    @Autowired
    private Queue BankMessage;
    @Autowired
    private Producer producer;

    @RequestMapping("send")
    public String testSendOneMessage(){
        Date date = new Date();
        producer.sendMessage(BankMessage,"我是mq:"+date.getTime());
        return "ok";
    }

    @RequestMapping("sendTopic")
    public String testSendTopic(){
        Date date = new Date();
        producer.sendTopicMessage("我是mqTopic:"+date.getTime());
        return "ok";
    }
    @RequestMapping("start")
    public String startMq() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setBrokerName("localMQ");
        broker.setUseJmx(true);//jmx监控
        broker.addConnector("tcp://localhost:61616");
        broker.start();
        return "ok";
    }
    @RequestMapping("stop")
    public String stopMq() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setBrokerName("localMQ");
        broker.setUseJmx(true);
        broker.addConnector("tcp://localhost:61616");
        broker.stop();
        return "ok";
    }

}
